<template>
  <div style="padding: 20px">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item prop="keyWord" label="关键字:">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请通过关键词搜索"
          clearable
          style="width: 15rem"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="societyAdd()"
        style="margin-bottom: 10px"
        v-hasPermi="['society:societyAdd:index']"
        >新增协会</el-button
      >
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="fullscreenLoading" :data="friSocietyList" style="width: 100%">
      <el-table-column label="序号" align="center" width="120">
        <template slot-scope="scope">
          <el-input  class="input" @blur="updateSort(scope.row.sort)" @focus="oldSort = scope.row.sort" v-model="scope.row.sort"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="协会Logo" align="center" width="300">
        <template slot-scope="scope">
          <img :src="scope.row.url" style="width:60px;height: 60px;border-radius: 50%;">
        </template>
      </el-table-column>
      <el-table-column prop="name" label="协会名称" align="center" width="300">
      </el-table-column>
      <el-table-column prop="content" align="center" label="协会简介">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="150"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="edit(scope.row.fid)"
            >编辑</el-button
          >
          <el-button size="mini" type="text" @click="delSociety(scope.row.fid)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { delByFid, saveFriendship, friendshipList,friSort } from "@/api/society";

export default {
  data() {
    return {
      //弹窗标题
      title: "",
      //参会人员列表
      friSocietyList: [],
      //活动id
      activityId: "",
      //总页数
      total: 0,
      //弹窗
      open: false,
      showSearch: true,
      //查询表单
      queryParams: {
        pageSize: 10,
        pageNum: 1,
        keyword: "",
      },
      //表单
      form: {
        name: "",
        content: "",
        url: "",
      },
      //图片
      commonFileRequests: "",
      //排序前的值
      oldSort:'',
      //排序后的值
      newSort:'',
      //屏幕加载
      fullscreenLoading: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //上传详情图片
    save(data) {
      this.form.commonFileRequests = [];
      this.commonFileRequests = data[0].url;
      this.form.url = data[0].url;
    },
    //获取列表
    getList() {
      let params = {
        ...this.queryParams,
      };
      friendshipList(params).then((res) => {
        if (res.code == 200) {
          this.friSocietyList = res.rows;
          this.friSocietyList.forEach((item, index) => {
            this.$set(item, "id", index + 1);
          });
        }
      });
    },
    //新增协会
    submit() {
      let params = {
        ...this.form,
      };
      saveFriendship(params).then((res) => {
        if (res.code == 200) {
          this.getList();
          this.reset();
          this.open = false;
        }
      });
    },
    //修改协会
    edit(fid) {
      this.$router.push({
        path: "/society/friSocietyEdit",
        query: { key: fid },
      });
    },
    //重置表单
    reset() {
      this.form = {
        name: "",
        content: "",
        url: "",
      };
    },
    //重置表单
    resetQuery() {
      this.queryParams = {
        pageSize: 10,
        pageNum: 1,
        keyword: "",
      };
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //添加新协会
    societyAdd() {
      this.$router.push({
        path: "/society/societyAdd",
      });
    },
    //删除友好协会
    delSociety(data) {
      this.$confirm("确认删除该协会信息?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delByFid(data).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //排序
    updateSort(newSort){
      let params = {
        oldSort:this.oldSort,
        newSort:Number(newSort)
      }
      this.fullscreenLoading = true;
      friSort(params).then(res =>{
        if(res.code == 200){
          this.getList()
          this.oldSort = ''
          this.fullscreenLoading = false
        }
      })
    },
  },
};
</script>
<style scoped>
.box {
  margin-top: -5px;
  line-height: 50px;
  width: 600px;
  height: 100px;
  background: #f8f8f9;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  font-weight: 400;
  overflow: hidden;
  z-index: 2;
  font-family: Microsoft YaHei;
}
.newbox:hover {
  background: #ebf3fb;
}
.newbox {
  width: 600px;
  height: 360px;
  line-height: 360px;
  border: 1px dashed gainsboro;
  text-align: center;
  font-size: 20px;
}
.label {
  height: 30px;
  width: 60px;
  margin-left: -40px;
  padding-left: 5px;
  background-color: #ebf3fb;
  margin-top: -5px;
  transition: 0.5s ease;
  line-height: 30px;
  z-index: 1;
  clip-path: polygon(0 0, 100% 0, 75% 50%, 100% 100%, 0 100%);
}
.label:hover {
  margin-left: 0px;
  background-color: rgb(178, 188, 191);
  margin-top: -5px;
}
/* 去除边框 */
::v-deep .el-input--medium .el-input__inner {
    height: 36px;
    line-height: 36px;
    width: 50px;
    padding: 10px;
    border: none;
}
::v-deep .el-table__row:hover{
  background: white;
}
</style>
